using UnityEngine;
using UnityEditor;
using System.Collections;
using Pathfinding;

[CustomGraphEditor (typeof(ListGraph),"ListGraph")]
public class ListGraphEditor : GraphEditor {

	public override void OnInspectorGUI (NavGraph target) {
		ListGraph graph = target as ListGraph;
		 
#if UNITY_3_3
		graph.root = (Transform)EditorGUILayout.ObjectField ("Root",graph.root,typeof(Transform));
#else
		graph.root = (Transform)EditorGUILayout.ObjectField ("Root",graph.root,typeof(Transform),true);
#endif
		graph.maxDistance = EditorGUILayout.FloatField ("Max Distance",graph.maxDistance);
		graph.limits = EditorGUILayout.Vector3Field ("Max Distance (axis aligned)",graph.limits);
		graph.raycast = EditorGUILayout.Toggle ("Raycast",graph.raycast);
		 
		editor.GUILayoutx.BeginFadeArea (graph.raycast,"raycast");
			
			EditorGUI.indentLevel++;
			
		 	graph.thickRaycast = EditorGUILayout.Toggle ("Thick Raycast",graph.thickRaycast);
		 	
		 	editor.GUILayoutx.BeginFadeArea (graph.thickRaycast,"thickRaycast");
		 	
		 		graph.thickRaycastRadius = EditorGUILayout.FloatField ("Raycast Radius",graph.thickRaycastRadius);
		 	
		 	editor.GUILayoutx.EndFadeArea ();
		 	
			//graph.mask = 1 << EditorGUILayout.LayerField ("Mask",(int)Mathf.Log (graph.mask,2));
			graph.mask = EditorGUILayoutx.LayerMaskField ("Mask",graph.mask);
			EditorGUI.indentLevel--;
			
		editor.GUILayoutx.EndFadeArea ();
	}
	
	public override void OnDrawGizmos () {
			
		ListGraph graph = target as ListGraph;
		
		//Debug.Log ("Gizmos "+(graph == null)+" "+target);
		if (graph == null) {
			return;
		}
		
		if (graph.root == null) {
			return;
		}
		
		//Handles.color = new Color (0.161F,0.341F,1F,0.5F);
		Gizmos.color = new Color (0.161F,0.341F,1F,0.5F);
		//for (int i=0;i<graph.nodes.Length;i++) {
		foreach (Transform child in graph.root) {
			Gizmos.DrawCube (child.position,Vector3.one*HandleUtility.GetHandleSize(child.position)*0.1F);
			//Handles.CubeCap (-1,graph.nodes[i].position,Quaternion.identity,HandleUtility.GetHandleSize(graph.nodes[i].position)*0.1F);
			//Gizmos.DrawCube (nodes[i].position,Vector3.one);
		}
	}
}
